package com.sunday.aomicaichang.ui.coupon;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.flyco.tablayout.SlidingTabLayout;
import com.sunday.common.adapter.MainFragmentPagerAdapter;
import com.sunday.common.base.BaseActivity;
import com.sunday.aomicaichang.R;
import com.sunday.aomicaichang.constValues.ConstValue;
import com.sunday.aomicaichang.http.ApiClient;
import com.sunday.aomicaichang.ui.common.WebViewActivity;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class CouponActivity extends BaseActivity {

    @Bind(R.id.slide_tab)
    SlidingTabLayout slideTab;
    @Bind(R.id.view_pager)
    ViewPager viewPager;

    private ArrayList<Fragment> fragments = new ArrayList<>();
    private final String[] mTitles = {
            "未使用", "已使用", "全部"
    };
    private String amount;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_coupon);
        ButterKnife.bind(this);
        amount = getIntent().getStringExtra("amount");
        initView();

    }

    @OnClick({R.id.rule})
    void onClick(View v) {
        switch (v.getId()) {
            case R.id.rule:
                intent = new Intent(mContext, WebViewActivity.class);
                intent.putExtra("url", ApiClient.API_URL1+"sunday/mobile/advertisement/html5ByZoneCode?zoneKey=coupon_rule" );
                intent.putExtra("title","优惠券说明");
                startActivity(intent);
                break;
        }
    }

    private void initView() {
        fragments.add(CouponFragment.newInstance(ConstValue.NOT_USED, amount));
        fragments.add(CouponFragment.newInstance(ConstValue.USERED, amount));
        fragments.add(CouponFragment.newInstance(ConstValue.ALL, amount));
        viewPager.setAdapter(new MainFragmentPagerAdapter(getSupportFragmentManager(), mContext, fragments,
                R.array.buy_order_list_title));
        slideTab.setViewPager(viewPager, mTitles, this, fragments);
        viewPager.setCurrentItem(0, false);
    }
}
